! 函数作为函数指针变量传递
module fdemo4

    implicit none

    procedure(fcn), pointer :: op => null()

    abstract interface
        pure subroutine fcn(x, y, z)
            integer, intent(in) :: x, y
            integer, intent(out) :: z
        end subroutine fcn
    end interface

contains

    pure subroutine add(x, y, z)
        integer, intent(in) :: x, y
        integer, intent(out) :: z
        z = x + y
    end subroutine add

    pure subroutine subtract(x, y, z)
        integer, intent(in) :: x, y
        integer, intent(out) :: z
        z = x - y
    end subroutine subtract

end module fdemo4

program main

    use fdemo4
    implicit none

    integer :: x, y, z

    x = 1
    y = 2
    op => add
    call op(x, y, z)
    print *, z

    x = 1
    y = 2
    op => subtract
    call op(x, y, z)
    print *, z

end program main
